package com.david.equipment.service.impl;

import ch.qos.logback.core.model.processor.ProcessorException;
import com.david.common.exception.EquipmentException;
import com.david.equipment.mapper.ProcessMapper;
import com.david.equipment.pojo.entity.EquipProcess;
import com.david.equipment.service.ProcessService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class ProcessServiceImpl implements ProcessService {
    final ProcessMapper processMapper;
    @Override
    public List<EquipProcess> getlist() {
        EquipProcess equipProcess = EquipProcess.builder().build();
        List<EquipProcess> list = processMapper.selectList(equipProcess);
        return list;
    }

    @Override
    public String editProcess(EquipProcess process) {
        if (processMapper.selectList(process).isEmpty()){
            throw new EquipmentException("流程配置不存在");
        } else {
            process.setUpdateTime(LocalDateTime.now());
            processMapper.updateProcess(process);
            return "流程配置修改成功";
        }

    }
}
